<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param Schedule $schedule
     * @return void`
     */
    protected function schedule(Schedule $schedule)
    {
        //commands定时任务
        $schedule->command('command:check_order')->everyMinute()->runInBackground();// 每分钟检查未支付完成订单的支付结果

        $schedule->command('command:explore_check')->everyMinute()->runInBackground();// 探店：每分钟检查已验收工单公示结束时间，进入待结算状态
        $schedule->command('command:explore_acceptance')->everyMinute()->runInBackground();// 探店：每分钟检查是否有未验收的工单，超时未验收的自动验收通过

        $schedule->command('command:explore_message')->dailyAt('10:00');// 探店：每天10点检查剩余单量，如果剩余待接单的单量超过阈值，进行一次全员推送
        $schedule->command('command:lottery_message')->dailyAt('14:00');// 霸王餐：每天14点检查剩余单量，对正在进行活动城市的达人进行一次全员推送

        // 生产环境和开发环境执行频率不同
        if(env('APP_ENV') === 'production'){
            $schedule->command('command:explore_overtime')->daily();// 探店：每天0点检查工单投稿过期并刷新，如果超过3天未投稿则取消订单
            $schedule->command('command:explore_remind')->dailyAt('12:00');// 探店：每天中午12点检查工单投稿过期并刷新，每天发送提醒通知
        } else {
            // 开发环境每分钟执行
            $schedule->command('command:explore_overtime')->hourly();// 探店：每小时检查工单投稿过期并刷新，超过1小时未投稿则取消订单
            $schedule->command('command:explore_remind')->everyThirtyMinutes();// 探店：每半小时检查工单投稿过期并刷新，每天发送提醒通知
            $schedule->command('command:lottery_message')->everyTenMinutes();// 霸王餐：每分钟一次，对正在进行活动城市的达人进行一次全员推送
////             非生产环境，每分钟执行一次测试脚本
//            $schedule->command('command:testing')->everyMinute();// 测试脚本，每分钟执行一次
        }

        $schedule->command('command:redpack_expired')->everyTenMinutes();// 探店：每分钟检查红包状态

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
